package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/messages")
@RestController
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    @PostMapping("/contacts")//添加联系人方法
    public ResponseEntity contacts(@RequestBody Map map){
        //1.接收参数
        String id = map.get("userId").toString();
        Long userId = Long.valueOf(id);
        //2.调用service处理
        messagesService.contacts(userId);
        //3.没有返回值
        return ResponseEntity.ok(null);
    }

    @GetMapping("/contacts")
    public ResponseEntity contacts(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize){
        //1.接收分页参数
        //2.调用service处理
        PageResult vo=messagesService.findFriends(page,pagesize);
        //3.返回结果
        return ResponseEntity.ok(vo);

    }
}
